<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>Zabbix自定义监控脚本配置 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>Zabbix自定义监控脚本配置</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注：要添加自定义脚本监控，必须升级zabbix agent版本至2.0.0以上，这里以2.0.8为例</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;配置方式：</p>
<ol>
<li>完成自定义监控脚本的编写（windows或linux脚本）</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;脚本要求：</p>
<ul>
<li>既然是监控，那必然要有输出结果值（字符串，数字皆可） </li>
<li>必须要求zabbix用户有执行权限，当然可以直接设置所有用户都有执行权限（chmod 777 脚本文件）</li>
<li>若脚本需要传入参数，按照参数传入的顺序，在脚本中可用$1-$9来引用传入的参数</li>
</ul>
<ol>
<li>找到zabbix agent的配置文件zabbix_agentd.conf,修改如下两个参数</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">UnsafeUserParameters=0 =&gt; UnsafeUserParameters=1  <span class="comment">#并去掉前面的注释符</span></div><div class="line">UserParameter= =&gt; UserParameter=aaa.bbb[*], /usr/<span class="built_in">local</span>/script/monitor.sh <span class="variable">$1</span> <span class="variable">$2</span> ...</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：aaa.bbb[*] —zabbix服务器添加监控信息时需要用到的key值，</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;格式：<br>aaa.bbb<a href="例：system.file.size[*]">*</a> /usr/local/script/monitor.sh —-监控脚本绝对路径</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;为了便于灵活监控，有时脚本需要传入参数，此参数可从zabbix服务器端传入，所有参数按顺序分别从$1-$9表示</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注：</p>
<ul>
<li>若无需传入参数，则红色部分可省略</li>
<li>该自定义脚本可由zabbix服务器控制收集数据的频率（如：每30s运行一次），无需再添加计划任务</li>
<li>以上参数请根据实际情况填写，并注意去除参数前注释符(#)</li>
<li>注意在key值和后面的脚本之间有个逗号隔开</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;至此，自定义监控脚本zabbix agent端配置结束</p>
<ol>
<li>测试</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;测试命令: </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">/usr/<span class="built_in">local</span>/bin/zabbix_agentd -t key[参数]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">/usr/<span class="built_in">local</span>/bin/zabbix_agentd -t system.file.size[/etc/a.txt,abc,...]</div></pre></td></tr></table></figure>
<ol>
<li>监控脚本举例：</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;脚本名称：/usr/local/script/monitor.sh</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;脚本内容：echo <code>date +&quot;%F %T&quot;</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;脚本要求：必须在控制台输出值，该值将作为返回值返回给zabbix服务器端</p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Zabbix/4. Zabbix自定义监控脚本配置/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
